$(document).ready(function() {	
	var url;
	
	if(document.domain=="localhost")
	{
		url="http://localhost/lifeinclass/admin/php/school.php";
	}else{
		url="http://lifeinclass.com/admin/php/school.php";
	}
	
	$.ajax({
	url: url,
	type: 'GET',
	dataType: "json",
	data: '',
	success: function(data) {
		if(data.error=="false")
		{
			for(var x=0;x<(data.list.length);x++)
			{
			var htmlAppend ="<tr>"
                                    +"<td align=\"center\">"+ (x+1) +"</td>"
                                    +"<td>"+data.list[x].school+"</td>"
                                    +"<td>"+data.list[x].name+"</td>"
                                    +"<td>"+data.list[x].email+"</td>"
                                    +"<td>"+data.list[x].phone+"</td>"
									+"<td>"+data.list[x].password+"</td>"
									+"<td>"+data.list[x].state+"</td>"
                                    +"<td>"+data.list[x].city+"</td>";
											
				if(data.list[x].activate == 0)
				{
					htmlAppend = htmlAppend + "<td align=\"center\"><button class=\"btn btn-success btn-xs\" onclick=\"activateDeactivate('"+data.list[x].id+"','activate')\">Activate</button></td></tr>";
				}else{
					htmlAppend = htmlAppend + "<td align=\"center\"><button class=\"btn btn-danger btn-xs\" onclick=\"activateDeactivate('"+data.list[x].id+"','deactivate')\">Deactivate</button></td></tr>";
				}
											
				$("#schools_table").last().append(htmlAppend);	   
			}		
		}
	},
	error: function(e) {
		console.debug("error");
	}
	});
});

function activateDeactivate(id,req)
{
	var activateordeactivate;
	if(req =="activate")
		activateordeactivate = 1;
		
	if(req =="deactivate")
		activateordeactivate = 0;

	var data = {
		"id": id,
		"request": activateordeactivate
	}; 
	
	if(document.domain=="localhost")
	{
		url="http://localhost/lifeinclass/admin/php/activate.php";
	}else{
		url="http://lifeinclass.com/admin/php/activate.php";
	}
	
	$.ajax({
		type: "POST",
		dataType: "json",
		url: url, 
		data: data,
		success: function(data) {
			console.debug(data);
			if(data.error == "false"){
				location.reload();
			}
		},
		error: function(e) {
			console.debug(e);
		}
	});
}